
package kaizone.haining.chaobohui.widget;

import kaizone.haining.chaobohui.R;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

public class CBHBotttom extends LinearLayout implements OnClickListener {

    private Fragment mAttchedFragment;

    private OnClickListener mListener;

    public final static int FLAG_SHOUYE = 0;

    public final static int FLAG_TUSHUO = 1;

    public final static int FLAG_HUODONG = 2;

    public final static int FLAG_WODE = 3;

    public int sFlag;

    public CBHBotttom(Context context) {
        super(context);
    }

    public CBHBotttom(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {

    }

    public void restore() {
        ((Button) findViewById(R.id.shouye)).setBackgroundResource(R.drawable.bottombtn_shouye);
        ((Button) findViewById(R.id.tushuo)).setBackgroundResource(R.drawable.bottombtn_tushuo);
        ((Button) findViewById(R.id.huodong)).setBackgroundResource(R.drawable.bottombtn_huodong);
        ((Button) findViewById(R.id.wode)).setBackgroundResource(R.drawable.bottombtn_wode);
    }

    public void flagShouye() {
        sFlag = FLAG_SHOUYE;
        ((Button) findViewById(R.id.shouye)).setBackgroundResource(R.drawable.bottombtn_shouyeon);
    }

    public void flagTushuo() {
        sFlag = FLAG_TUSHUO;
        ((Button) findViewById(R.id.tushuo)).setBackgroundResource(R.drawable.bottombtn_tushuoon);
    }

    public void flagHuodong() {
        sFlag = FLAG_HUODONG;
        ((Button) findViewById(R.id.huodong)).setBackgroundResource(R.drawable.bottombtn_huodongon);
    }

    public void flagWode() {
        sFlag = FLAG_WODE;
        ((Button) findViewById(R.id.wode)).setBackgroundResource(R.drawable.bottombtn_wodeon);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ((Button) findViewById(R.id.shouye)).setOnClickListener(this);
        ((Button) findViewById(R.id.tushuo)).setOnClickListener(this);
        ((Button) findViewById(R.id.huodong)).setOnClickListener(this);
        ((Button) findViewById(R.id.wode)).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        restore();
        if (v.getId() == R.id.shouye) {
            flagShouye();
            if (mListener != null) {
                mListener.onShouYe();
            }
        }
        //
        else if (v.getId() == R.id.tushuo) {
            flagTushuo();
            if (mListener != null) {
                mListener.onTuShuo();
            }
        }
        //
        else if (v.getId() == R.id.huodong) {
            flagHuodong();
            if (mListener != null) {
                mListener.onHuodong();
            }
        }
        //
        else if (v.getId() == R.id.wode) {
            flagWode();
            if (mListener != null) {
                mListener.onWode();
            }
        }
    }

    public void addAttched(Fragment fragment) {
        mAttchedFragment = fragment;
    }

    public void setListener(OnClickListener listener) {
        mListener = listener;
    }

    public interface OnClickListener {
        void onShouYe();

        void onTuShuo();

        void onHuodong();

        void onWode();
    }
}
